<template>
    <div class="select_class">
        <header ><a @click="$api.goBack()" class="back"></a><span>反馈记录</span></header>
        <mt-index-list>
            <mt-index-section class="section" v-for="year in AllYear" :key=year :index="year">
                <div class="main" v-for="(item,index) in showData" @click="showDetail(index)" v-if="new Date(item.createTime).Format('yyyy')==year">
                    <div class="flex">
                        <div class="classroom">
                            <div class="className">{{formatterType(item.backType)}}</div>
                            <div class="teacher">{{new Date(item.createTime).Format("yyyy-MM-dd hh:mm:ss")}}</div>
                        </div>
                    </div>     
                </div>
            </mt-index-section>
        </mt-index-list>
    </div>
    
</template>

<script>
    export default {
        data() {
            return {
                pageNum: 1,
                pageSize: 10000,
                showData: [],
                useInfo: '',
            }
        },
        computed: {
            AllYear: function() {
                var array = [];
                let AllYear = this.showData.map(x => { //从 showData里面提取以年为子对象的数组
                    var sortName = new Date(x.createTime).Format("yyyy");
                    return sortName
                })
                AllYear = AllYear.filter((element, index, self) => { //过滤相同子节点
                    return self.indexOf(element) === index;
                })
                return AllYear;
            }
        },
        created() {
            this.getUserInfo();
            this.getDetail();

        },
        methods: {
            getUserInfo() {
                this.useInfo = JSON.parse(sessionStorage.getItem('useInfo'));
            },
            getDetail() {
                var params = {
                    pageNum: this.pageNum,
                    pageSize: this.pageSize,
                    schoolId: this.useInfo.schoolId,
                }
                if (this.useInfo.userTypeId == '4') {
                    params.userId = this.useInfo.userId
                }
                var url = "/feedback/selectPage"
                this.$api.post(url, params, (data) => {
                    this.showData = data.info.list;

                    console.log(JSON.parse(JSON.stringify(data)));
                })
            },
            formatterType(id) {
                switch (id) {
                    case 1:
                        return "使用异常";
                        break;
                    case 2:
                        return "意见反馈";
                        break;
                    default:
                        return "其他";
                        break;
                }
            },
            showDetail(index) {
                var detail = this.showData[index];
                sessionStorage.setItem('feedDetail', JSON.stringify(detail));
                this.$router.push({
                    'path': 'feedDetail'
                })
            }
        }

    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>